package de.tabiteuea.gui.utils;

import java.io.IOException;
import java.net.URL;

import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

import de.tabiteuea.gui.Activator;

/**
 * 
 * Provides the methods to get specific images.
 * 
 * @author Sebastian Lippert
 * 
 */

public class ImageProvider {

	/**
	 * Gets the specific image from the icons folder.
	 * 
	 * @param path
	 *            to the image
	 * @return Image icon
	 */

	public static Image getImage(String path) {

		ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry();
		Image img = imageRegistry.get(path);

		if (img == null) {
			try {
				URL url = Activator.getDefault().getBundle().getEntry(path);
				img = new Image(Display.getCurrent(), url.openStream());
				imageRegistry.put(path, img);
			} catch (IOException e) {
				Activator.logException(e);
			}
		}

		return img;

	}

	/**
	 * Gets the specific image from the eclipse framework.
	 * 
	 * @param symbolicName
	 *            Name of the icon
	 * @return Image icon
	 */

	public static Image getSharedImage(String symbolicName) {

		return PlatformUI.getWorkbench().getSharedImages()
				.getImage(symbolicName);

	}

}
